import Vue from 'vue'
// 引入 路由包
import VueRouter from 'vue-router'
// 引入 首页的 组件
import MovieView from '../views/home/MovieView.vue'

//使用路由插件
Vue.use(VueRouter)

//路由表文件
const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    name: 'home',//路由名字
    component: MovieView,
    children: [
      { path: '/home', redirect: '/home/reying' },
      { path: 'reying', name: 'reying', component: () => import(/* webpackChunkName: "reying" */ '../views/home/ReYing.vue') },
      { path: 'yingyuan', name: 'yingyuan', component: () => import(/* webpackChunkName: "yingyuan" */ '../views/home/YingYuan.vue') },
      { path: 'daiying', name: 'daiying', component: () => import(/* webpackChunkName: "daiying" */ '../views/home/DaiYing.vue') },
      { path: 'jingdian', name: 'jingdian', component: () => import(/* webpackChunkName: "jingdian" */ '../views/home/JingDian.vue') },
    ]
  },
  {
    path: '/video',
    name: 'video',
    // 路由懒加载，路由到该页面时才会加载相关信息，
    component: () => import(/* webpackChunkName: "video" */ '../views/VideoView.vue')
  },
  {
    path: '/shortvideo',
    name: 'shortvideo',
    component: () => import(/* webpackChunkName: "shortvideo" */ '../views/ShortVideoView.vue')
  },
  {
    path: '/show',
    name: 'show',
    component: () => import(/* webpackChunkName: "show" */ '../views/ShowView.vue')
  },
  {
    path: '/me',
    name: 'me',
    component: () => import(/* webpackChunkName: "me" */ '../views/MeView.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import(/* webpackChunkName: "login" */ '../views/LoginView.vue')
  },
  {
    path: '/city',
    name: 'city',
    component: () => import(/* webpackChunkName: "city" */ '../views/CityList.vue')
  },
  {
    path: '/item/:itemid',
    name: 'item',
    component: () => import(/* webpackChunkName: "item" */ '../views/ItemView.vue')
  }, {
    path: '*',
    component: () => import(/* webpackChunkName: "fzf" */ '../views/FzFpage.vue')
  }
]

// 创建路由对象
const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  if (to.path == '/me') {
    if (sessionStorage.getItem('user')) {
      next();
    } else {
      next('/login')
    }
  } else {
    next()
  }
})

export default router
